App({
    onLaunch(options) {
        console.log('app.js onLaunch====', options)
    },
    onShow(options) {
        console.log('app.js onShow====', options)
        //如果是第三方小程序跳转
        if(options.referrerInfo.extraData != undefined && options.referrerInfo.extraData.code != undefined) {
            let data = options.referrerInfo.extraData;
            wx.setStorageSync('login', data); //登录用

            if(data.code == 'community') { //从邕居家园跳转过来
                wx.setStorageSync('shop', data); //查询店铺用
                wx.navigateTo({
                    url: '/pages/storeIndex/storeIndex',
                });
            }
        }
    },

    //全局通用方法
    filterPhone(phone) { //处理电话号码
        let val = '****' + phone.slice(7, 11);
        return val;
    },
    filterDate(val) { //处理日期时间
        let date = new Date(val);
        let year = date.getFullYear();
        let month = date.getMonth() + 1;
        let day = date.getDate();
        let hour = date.getHours();
        let minute = date.getMinutes();
        let second = date.getSeconds();
        let fullTime = year + '-' + this.checkNumber(month) + '-' + this.checkNumber(day) + ' ' + this.checkNumber(hour) + ':' + this.checkNumber(minute) + ':' + this.checkNumber(second);
        return fullTime;
    },
    objDeepCopy (source) { //深拷贝
        let sourceCopy = source instanceof Array ? [] : {};
        for (let item in source) {
            sourceCopy[item] = typeof source[item] === 'object' ? this.objDeepCopy(source[item]) : source[item];
        }
        return sourceCopy;
    },
    checkNumber(i) { //时间补零
        if(i < 10) {
            i = '0' + i;
        }
        return i;
    },

    globalData: {
        userInfo: '',
        isCanAutoLogin: true, //是否可以自动登录

        isRefreshIndex: false, //是否刷新首页
        isRefreshStore: false, //是否刷新店铺信息
        isRefreshPickipStore: false, //是否刷新提货店铺
        isRefreshCategory: false, //是否刷新分类信息
        isRefreshShopcart: false, //是否刷新购物车
        shopcartCacheList: [],
    }
})
